package com.masterlu.module.product.convert.liked;

import com.masterlu.module.product.controller.app.liked.vo.AppLikedRespVO;
import com.masterlu.module.product.dal.dataobject.liked.ProductLikedDO;
import com.masterlu.module.product.dal.dataobject.spu.ProductSpuDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static com.masterlu.framework.common.util.collection.CollectionUtils.convertMap;

@Mapper
public interface ProductLikedConvert {

    ProductLikedConvert INSTANCE = Mappers.getMapper(ProductLikedConvert.class);

    ProductLikedDO convert(Long userId, Long commentId);
    ProductLikedDO convert2(Long userId, Long commentId,Boolean deleted);

    @Mapping(target = "id", source = "liked.id")
    @Mapping(target = "commentName", source = "comment.name")
/*    AppLikedRespVO convert(ProductSpuDO spu, ProductLikedDO liked);*/

    default List<AppLikedRespVO> convertList(List<ProductLikedDO> likeds, List<ProductSpuDO> spus) {
        List<AppLikedRespVO> resultList = new ArrayList<>(likeds.size());
        Map<Long, ProductSpuDO> spuMap = convertMap(spus, ProductSpuDO::getId);

        /*TODO:   lujisen*/
   /*     for (ProductLikedDO liked : likeds) {
            ProductSpuDO spuDO = spuMap.get(liked.getCommentId());
            resultList.add(convert(spuDO, liked));
        }*/
        return resultList;
    }

/*    default PageResult<ProductLikedRespVO> convertPage(PageResult<ProductLikedDO> pageResult, List<ProductSpuDO> spuList) {
        Map<Long, ProductSpuDO> spuMap = convertMap(spuList, ProductSpuDO::getId);
        List<ProductLikedRespVO> voList = CollectionUtils.convertList(pageResult.getList(), liked -> {
            ProductSpuDO spu = spuMap.get(liked.getCommentId());
            return convert02(spu, liked);
        });
        return new PageResult<>(voList, pageResult.getTotal());
    }*/
/*    @Mapping(target = "id", source = "liked.id")
    @Mapping(target = "userId", source = "liked.userId")
    @Mapping(target = "commentId", source = "liked.commentId")
    @Mapping(target = "createTime", source = "liked.createTime")
    ProductLikedRespVO convert02(ProductSpuDO spu, ProductLikedDO liked);*/

}
